home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 November / Cd users extra 14.iso / prog / inst / mailc / reader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-14  |  2.7 KB  |  96 lines

  1. /*
  2. **  READER.C [edit EMAIL.H before compiling]
  3. **
  4. **  This program reads the specified email message
  5. **  and saves it to disk.
  6. */
  7.  
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "see.h"
  12. #include "email.h"
  13.  
  14. #define QUOTE 0x22
  15.  
  16. static char Buffer[1024];
  17.  
  18. void ErrorExit(int Code)
  19. {seeErrorText(Code,(LPSTR)Buffer,512);
  20.  printf("SEE Error %d: %s\n", Code, Buffer);
  21.  seeClose();
  22.  exit(1);
  23. }
  24.  
  25. void main(int argc, char *argv[])
  26. {int i, Code; 
  27.  int Count;
  28.  int MsgNbr;
  29.  long MsgSize;
  30.  long BytesRead = 0;
  31.  if(argc!=3)
  32.    {printf("Usage: READER MsgNbr Filename\n");
  33.     printf("   eg: READER 1 message.mai\n");    
  34.     exit(1);
  35.    }
  36.    
  37.  /* display parameters */
  38.  printf("Server : %s\n",(LPSTR)POP3_HOST_NAME);
  39.  printf("  User : %s\n",(LPSTR)POP3_USER_NAME);
  40.  printf("  Pass : %s\n",(LPSTR)POP3_PASSWORD);
  41.  printf("Messge : %s\n",(LPSTR)argv[1] );
  42.  printf("SaveTo : %s\n",(LPSTR)argv[2]);
  43.  
  44.  MsgNbr = atoi(argv[1]); 
  45.  if((MsgNbr<1)||(MsgNbr>1000))
  46.    {printf("MsgNbr = %d out of range\n", MsgNbr);
  47.     exit(1);
  48.    }
  49.  /* define diagnostics log file */
  50.  ///seeStringParam(SEE_LOG_FILE, (LPSTR)"reader.log"); 
  51.  /* connect to POP3 server */
  52.  puts("Connecting...");
  53.  Code = seePop3Connect(
  54.     (LPSTR)POP3_HOST_NAME,             /* POP3 server */
  55.     (LPSTR)POP3_USER_NAME,             /* user */ 
  56.     (LPSTR)POP3_PASSWORD);             /* Password */
  57.  if(Code<0) ErrorExit(Code); 
  58.  /* get # messages waiting  */
  59.  puts("Getting message count...");
  60.  Count = seeGetEmailCount();                   
  61.  if(Count<0) ErrorExit(Count); 
  62.  printf("%d messages waiting.\n", Count);
  63.  /* read email message */
  64.  if((Count>=1)&&(MsgNbr<=Count))
  65.    {/* read message  */
  66.     ///printf("Calling seeGetEmailSize(%d)...\n",MsgNbr);
  67.     MsgSize = seeGetEmailSize(MsgNbr);
  68.     if(MsgSize<0) ErrorExit((int)MsgSize);
  69.     printf("Message %d has %ld bytes\n", MsgNbr, MsgSize);    
  70.     /* turn off AUTO CALL driver */
  71.     seeIntegerParam(SEE_AUTO_CALL_DRIVER, 0); 
  72.     printf("Reading message %d...\n",MsgNbr);
  73.     Code = seeGetEmailFile(MsgNbr, argv[2], ".", ".");
  74.     if(Code<0) ErrorExit(Code);
  75.     /* run the driver */
  76.     for(i=0;;i++)
  77.       {Code = seeDriver();
  78.        if(Code<0) ErrorExit(Code);
  79.        if(((i%10)==9)||(Code==0))
  80.          {/* display progress on last call & every 10th call to seeDriver() */
  81.           BytesRead = (long) seeStatistics(SEE_GET_TOTAL_BYTES_READ);
  82.           printf("%ld bytes read.\r",BytesRead);
  83.          }
  84.        if(Code==0) break;
  85.        }
  86.     printf("\n");    
  87.     /* turn AUTO CALL back on for seeClose */
  88.     seeIntegerParam(SEE_AUTO_CALL_DRIVER, 1);
  89.     if(Code<0) ErrorExit(Code); 
  90.    }
  91.  else printf("No messages waiting\n");
  92.  seeClose();
  93. } /* end main */
  94.  
  95.  
  96.